﻿@using Resources
@using Webdiyer.WebControls.Mvc
@model PagedList<NetSurveillance.WebApp.DataServices.Models.QQPassword>
@{
    ViewBag.Title = "QQMonitorList";
    Layout = "~/Views/Shared/_SimpleLayout.cshtml";    
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary()
    @Html.Hidden("hostIds")
    <div class="showdia_qq_content">
        <div class="showdia_qq_left">
            <div class="showdia_qq_left_title">
                @ViewResource.HostListTitle
            </div>
            <div class="showdia_qq_left_tree">
                @Html.Partial("../Host/_HostTree", ViewBag.TreeNode as string)
            </div>
            <div class="showdia_qq_left_bottom">
                <label>
                    @Html.CheckBox("isAutoMonitorHostForQQMonitor")
                    自动监控新主机
                </label>
            </div>
        </div>
        <div class="showdia_qq_middle_right">
            <div class="showdialog_qq_right_title">&nbsp;&nbsp;QQ列表</div>
            <table id="tbHeader" class="showdialog_qq_tab" style="border: none; width: 599px;">
                <tr>
                    <th>
                        <input type="checkbox" id="chk_showdialog_qq_tab_all" />
                    </th>
                    <th class="chk_showdialog_qq_tab_all_td" style="width: 180px;">QQ号</th>
                    <th>密码</th>
                    <th style="width: 300px;">最近一次解密密钥获取时间</th>
                </tr>
            </table>
            <div id="tab_content">
                <table id="tab_list" class="showdialog_qq_tab">
                    @foreach (var item in Model)
                    {
                        <tr data-entryId="@item.Id">
                            <td>
                                <input type="checkbox" class="chk_showdialog_qq_tab" name="showdialog_checkbox"
                                    value="@item.Id" />
                            </td>
                            <td style="width: 180px;" class="chk_showdialog_qq_tab_all_td">@item.Account</td>
                            <td class="chk_showdialog_td_center">@item.Password </td>
                            <td class="chk_showdialog_td_center">@item.LastModifiedTime</td>
                        </tr>
                    }
                </table>
                @Html.Pager(Model, new PagerOptions
                    {
                        PageIndexParameterName = "pageIndex",
                        CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",
                        NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",
                        CssClass = "pages",
                        SeparatorHtml = ""
                    })
            </div>
            <dl class="showdia_qq_right_btns">
                <dd>
                    <input type="button" value="@Resource.Button_ReLoad" id="showdia_qq_btn_refresh" onclick="reLoad();" />
                </dd>
                <dd>
                    @Html.ActionLink(Resource.Button_EnterByHand, "AddPassword", null, new { @class = "commonButton" })
                </dd>
                <dd>
                    <input type="button" value="@Resource.Button_Delete" id="showdia_qq_btn_del" />
                </dd>
                <dd>
                    @Html.ActionLink(Resource.Button_Export, "Export", null, new { @class = "commonButton" })
                </dd>
                <dd>
                    @Html.ActionLink(Resource.Button_Import, "Import", null, new { @class = "commonButton" })
                </dd>
            </dl>

            <dl class="showdia_qq_right_bottom">
                <dd>
                    <label>
                        @Html.CheckBox("isAutoAlertQQMonitor")
                        自动报警
                    </label>
                </dd>
                <dd>
                    <img src="/content/images/showdia_qq_right_bottom_icon1.gif" width="10" height="16" />
                    说明：当列表中被监控QQ上线并成功解密时,将自动报警.
                </dd>
            </dl>
        </div>
        <div class="showdia_qq_bottom">
            <div class="showdia_qq_bottom_btns">
                <ul class="config_bottom_btndivs02">
                    <li>
                        <input type="submit" value="@Resource.Button_Update" id="btn_showdia_qq_update" />
                    </li>
                    <li>
                        <input type="button" value="@Resource.Button_Exit" id="btn_showdia_qq_exit"  onclick="windowClose();" />
                    </li>
                </ul>
            </div>
        </div>
    </div>   
}
@section css
{
    <style type="text/css">
        #tbHeader,#tab_list {
            border: 0;
            border-spacing: 0;
            border-collapse: collapse;
        }
        #tbHeader th,#tbHeader td,
        #tab_list th,#tab_list td {
            text-align: center;
        }
    </style>
}
@section javascript
{
    <script type="text/javascript">
        $(function() {
            $("#showdia_qq_btn_del").bind("click", deleteEntries);
            $('#btn_showdia_qq_update').click(saveEntry);
            $('#chk_showdialog_qq_tab_all').click(selectAll);
        });

        function saveEntry() {
            $('#hostIds').val(JSON.stringify(getCheckHostIds()));
            return true;
        }

        function reLoad() {
            window.location.href = '@Url.Action("QQPasswordsManager")';
        }

        function selectAll() {
            $("#tab_list :checkbox").attr("checked", this.checked);
        }

        function windowClose() {
            if (confirm("您确定要退出吗？")) {
                window.open("", "_self");
                top.opener = null;
                top.close();
            }
        }

        function deleteEntries() {
            var qqPassIdArr = $.map($('#tab_list :checkbox:checked'), function(ele) {
                return $(ele).val();
            });
            if (qqPassIdArr.length > 0 && window.confirm('@MessageResource.Delete_Confirm')) {
                $.showLoading('@MessageResource.Delete_Loading');
                $.ajax({
                    url: '@Url.Action("DeleteQQPasswords")',
                    type: 'post',
                    dataType: 'json',
                    traditional: true,
                    data: { qqPassIds: qqPassIdArr },
                    success: function(result) {
                        if (result.success) {
                            $('#tab_list tr:has(:checkbox:checked)').remove();
                        } else {
                            alert(result.message);
                        }
                        $.hideLoading();
                    }
                });
            }
        }
    </script>
}
